package com.codepoem.designpattern.observer

/**
 * 抽象通知者
 */
abstract class Subject {

    private var observers = arrayListOf<Observer>()

    fun attach(observer: Observer) {
        observers.add(observer)
    }

    fun detach(observer: Observer) {
        observers.remove(observer)
    }

    fun notifyObservers() {
        for (observer in observers) {
            observer.update()
        }
    }
}